<?php
require './script/mysqlconfig.php';
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

function num($devicetype) {
//    echo "Hello, " . $name . "!";
    $sql = "SELECT COUNT(*) AS number FROM hosts WHERE device_type = '$devicetype' ";
    global $conn;
    $result = $conn->query($sql);
    $row = $result->fetch_assoc();
    return $row['number'];
}

$switchnum = num("交换机");
$routernum = num("路由器");
$firewallnum = num("防火墙");
$safetynum = num("安全设备");
$servicenum = num("服务器");
$storagenum = num("存储");
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>机房资源统计</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
        }

        h1 {
            color: #333;
            text-align: center;
        }

        .resource-container {
            background-color: #f5f5f5;
            padding: 20px;
            border-radius: 8px;
            margin-top: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 10px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
            font-weight: bold;
        }

        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
<h1>资产统计</h1>

<div class="resource-container">
    <table border="1" cellspacing="0">
        <thead>
        <tr>
            <th>资源类型</th>
            <th>数量</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><strong>交换机：</strong></td>
            <td><?php echo $switchnum; ?></td>
        </tr>
        <tr>
            <td><strong>路由器：</strong></td>
            <td><?php echo $routernum; ?></td>
        </tr>
        <tr>
            <td><strong>防火墙：</strong></td>
            <td><?php echo $firewallnum; ?></td>
        </tr>
        <tr>
            <td><strong>安全设备：</strong></td>
            <td><?php echo $safetynum; ?></td>
        </tr>
        <tr>
            <td><strong>服务器：</strong></td>
            <td><?php echo $servicenum; ?></td>
        </tr>
        <tr>
            <td><strong>存储：</strong></td>
            <td><?php echo $storagenum; ?></td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>


